// 引入博客封面utils
const blogfaceload = require('../utils/upload/blogfaceUploadUtils')
const  {avatarImgUpload ,swiperImgUpload,adImgUpload,blogFaceLoad,
     delAvatarImgUpload, delSwiperUpload,delAdUpload,delBlogFaceLoad,
     getSwipers ,getAds,
     sureAddSwiper,sureAddAd} = require('../service/upload.service')
module.exports = {
    // 头像上传
    avatarImgUpload: async (ctx,next)=>{
        await avatarImgUpload(ctx,next)
    },
    // 删除头像
    delAvatarImgUpload: async (ctx,next)=>{
        await delAvatarImgUpload(ctx,next)
    },


    // 上传轮播图
    swiperImgUpload: async (ctx,next)=>{
        await swiperImgUpload(ctx,next)
    },
    // 轮播图地址添加进数据库
     sureAddSwiper: async (ctx,next)=>{
        await sureAddSwiper(ctx,next)
    },
    // 删除轮播图
    delSwiperUpload: async (ctx,next)=>{
        await delSwiperUpload(ctx,next)
    },
    // 获取轮播图
    getSwipers: async (ctx,next)=>{
        await getSwipers(ctx,next)
    },


    // 广告图上传
    adImgUpload:async (ctx,next)=>{
        await adImgUpload(ctx,next)
    },
    // 删除广告
    delAdUpload: async (ctx,next)=>{
        await delAdUpload(ctx,next)
    },
    // 确认上传广告图
    sureAddAd: async (ctx,next)=>{
        await sureAddAd(ctx,next)
    },
    getAds: async (ctx,next)=>{
        await getAds(ctx,next)
    },
    // 博客封面上传
    blogFaceLoad: async (ctx,next)=>{
        await blogFaceLoad(ctx,next)
    },
    blogFaceErr: async (ctx,next)=>{
        let err = await blogfaceload.single('file')(ctx, next)
                    .then(res=>res)
                    .catch(err=>err)
        if(err){
            ctx.body = {
                code:201,
                msg : err.message
            }
        }
    },
    delBlogFaceLoad: async (ctx,next)=>{
        await delBlogFaceLoad(ctx,next)
    },
}
